From 7192e29aa7d0ab082979d480f142d41beb7713a8 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 28 Aug 2014 20:38:19 -0700 Subject: [PATCH] Dedup overrides by name Overrides are only queried by name, and it's possible for multiple to show up, and just pick the first one. Closes #461 --- src/cargo/core/registry.rs | 7 ++++- tests/test_cargo_compile_path_deps.rs | 44 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index 236f7e68c..614d41077 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -1,3 +1,5 @@ +use std::collections::HashSet; + use core::{Source, SourceId, SourceMap, Summary, Dependency, PackageId, Package}; use util::{CargoResult, ChainError, Config, human, profile}; @@ -100,11 +102,14 @@ impl<'a> PackageRegistry<'a> { fn query_overrides(&mut self, dep: &Dependency) -> CargoResult> { + let mut seen = HashSet::new(); let mut ret = Vec::new(); for s in self.overrides.iter() { let src = self.sources.get_mut(s).unwrap(); let dep = Dependency::new_override(dep.get_name(), s); - ret.push_all_move(try!(src.query(&dep))); + ret.extend(try!(src.query(&dep)).move_iter().filter(|s| { + seen.insert(s.get_name().to_string()) + })); } Ok(ret) } diff --git a/tests/test_cargo_compile_path_deps.rs b/tests/test_cargo_compile_path_deps.rs index 4385826c8..649a19009 100644 --- a/tests/test_cargo_compile_path_deps.rs +++ b/tests/test_cargo_compile_path_deps.rs @@ -569,3 +569,47 @@ test!(override_self { assert_that(p.cargo_process("build"), execs().with_status(0)); }) + +test!(override_path_dep { + let bar = project("bar") + .file("p1/Cargo.toml", r#" + [package] + name = "p1" + version = "0.5.0" + authors = [] + + [dependencies.p2] + path = "../p2" + "#) + .file("p1/src/lib.rs", "") + .file("p2/Cargo.toml", r#" + [package] + name = "p2" + version = "0.5.0" + authors = [] + "#) + .file("p2/src/lib.rs", ""); + + let p = project("foo") + .file(".cargo/config", format!(r#" + paths = ['{}', '{}'] + "#, bar.root().join("p1").display(), + bar.root().join("p2").display())) + .file("Cargo.toml", format!(r#" + [package] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [dependencies.p2] + path = '{}' + + "#, bar.root().join("p2").display())) + .file("src/lib.rs", ""); + + bar.build(); + assert_that(p.cargo_process("build").arg("-v"), + execs().with_status(0)); + +}) -- 2.30.2